package com.zy.openchat.core.model.circle;

import android.os.Parcel;
import android.os.Parcelable;

import com.zy.openchat.util.Common;

import java.util.ArrayList;
import java.util.List;

public class BlogPrivacyInfo implements Parcelable {

    public static final int DONT_LOOK_ME = 1;
    public static final int ME_DONT_LOOK = 2;
    public static final int FRIEND_LOOK_ME_SCOPE = 3;
    public static final int STRANGER_LOOK_ME_SCOPE = 4;

    public int key;
    public List<BlogRuleInfo> rules;

    public BlogRuleInfo getRule(){
        if(Common.isEmpty(rules)){
            return null;
        }
        return rules.get(0);
    }

    public static BlogPrivacyInfo build(int key){
        BlogPrivacyInfo handlePrivacyInfo = new BlogPrivacyInfo();
        handlePrivacyInfo.key = key;
        List<BlogRuleInfo> handleBlogRules = new ArrayList<>();
        BlogRuleInfo handleBlogRule = new BlogRuleInfo();
        handleBlogRules.add(handleBlogRule);
        handlePrivacyInfo.rules = handleBlogRules;
        return handlePrivacyInfo;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.key);
        dest.writeTypedList(this.rules);
    }

    public void readFromParcel(Parcel source) {
        this.key = source.readInt();
        this.rules = source.createTypedArrayList(BlogRuleInfo.CREATOR);
    }

    public BlogPrivacyInfo() {
    }

    protected BlogPrivacyInfo(Parcel in) {
        this.key = in.readInt();
        this.rules = in.createTypedArrayList(BlogRuleInfo.CREATOR);
    }

    public static final Parcelable.Creator<BlogPrivacyInfo> CREATOR = new Parcelable.Creator<BlogPrivacyInfo>() {
        @Override
        public BlogPrivacyInfo createFromParcel(Parcel source) {
            return new BlogPrivacyInfo(source);
        }

        @Override
        public BlogPrivacyInfo[] newArray(int size) {
            return new BlogPrivacyInfo[size];
        }
    };
}
